//
//  CouponData.swift
//  LoveFreshBeen
//
//  Created by Gao on 17/2/13.
//  Copyright © 2017年 Odm. All rights reserved.
//

import UIKit

class Coupon: NSObject {
    var id: String?
    var card_pwd: String?
    /// 开始时间
    var start_time: String?
    /// 结束时间
    var end_time: String?
    /// 金额
    var value: String?
    var tid: String?
    /// 是否被使用 0 使用 1 未使用
    var is_userd: String?
    /// 0 可使用 1 不可使用
    var status: Int = -1
    var true_end_time: String?
    /// 标题
    var name: String?
    var point: String?
    var type: String?
    var order_limit_money: String?
    var desc: String?
    var free_freight: String?
    var city: String?
    var ctime: String?

}

class CouponData: NSObject {

    var code: Int = -1
    var msg: String?
    var reqid: String?
    var data: [Coupon]?
    
    // 返回容器类中的所需要存放的数据类型 (以 Class 或 Class Name 的形式)。
    class func modelContainerPropertyGenericClass() -> [AnyHashable: Any] {
        return ["data": Coupon.self]
    }

    
    class func loadCouponData(_ completion:(_ data: CouponData?, _ error: NSError?) -> Void) {
        guard let path = Bundle.main.path(forResource: "MyCoupon", ofType: nil) else{
            return
        }
        
        let url = URL(fileURLWithPath: path)
        
        guard let jsonString = try? String(contentsOf: url) else{
            return
        }
        
        let couponData = CouponData.yy_model(withJSON: jsonString)
        
        if couponData != nil {
            completion(couponData, nil)
        }
        
    }
    
            
    
}
